package com.hy.domain.dto;

import com.hy.domain.Blog;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;
import java.util.Map;

@Data
@ApiModel("返回结果")
@AllArgsConstructor
@NoArgsConstructor
public class R1<T> {
    @ApiModelProperty("状态")
    private Boolean status;

    @ApiModelProperty("数据")
    private T data;

    @ApiModelProperty("信息")
    private String message;

    public R1(Boolean status, T data) {
        this.status = status;
        this.data = data;
    }

    public static<T> R1<T> ok() {
        return new R1<T>(true, null, "操作成功");
    }

//    public R<T> setData(T data) {
//        this.data = data;
//        return this;
//    }
//
//    public R<T> setMessage(String message) {
//        this.message = message;
//        return this;
//    }

    public static <T> R1 ok(T data) {
        return new R1(true, data);
    }

//    public static<T> R ok(String message) {
//        return new R(true, message);
//    }

    public static<T> R1<T> ok(T data, String message) {
        return new R1<T>(true, data, message);
    }

    public static<T> R1<T> fail() {
        return new R1<T>(false, null, "操作失败");
    }

    public static<T> R1<T> fail(T data) {
        return new R1<>(false, data);
    }

    public static R1<Blog> by(boolean status) {
        if (status) {
            return ok();
        } else {
            return fail();
        }
    }

    public R1<T> message(String msg){
        this.setMessage(msg);
        return this;
    }
}
